var map = '{map}';
var sysId;
var flag; // 操作标识
var editStatus = 0 ;

/**
 * 重置表单数据
 */
function resetData(formName, type) {
	$('#configForm').form('reset');
	$
			.ajax({
				url : 'platform/UseConfigController/findUseConfig',
				data : {},
				type : 'post',
				dataType : 'json',
				success : function(result) {
					if (result.map.DEFAULT_BORROW_TYPE == "1") {
						$("#yuanjian").attr('checked', true);
						$("#copy").attr('checked', false);
					} else {
						$("#yuanjian").attr('checked', false);
						$("#copy").attr('checked', true);
					}
					if (result.map.IS_HIGH_SET == "1") {
						$("#highSet").attr('checked', true);
						$('#myOrderDataGrid').datagrid("reload");
					} else {
						$("#highSet").attr('checked', false);
						var datas = $('#myOrderDataGrid').datagrid('getRows');
						for ( var i = 0; i < datas.length;) {
							$('#myOrderDataGrid').datagrid('deleteRow', 0);
						}
					}
					if (result.map.IS_BORROW_FORCAST == "1") {
						$("#autoBorrowReserve").attr('checked', true);
						document.getElementById("forcastQueueNum")
								.removeAttribute("style");
						$('#forcastOvertime').attr({
							style : "background-color: white ;width:180px"
						});
						$('#forcastOvertime').attr({
							style : "background-color: white ;width:180px"
						});

						$('#forcastQueueNum').attr("readonly", false);
						$('#forcastOvertime').attr("readonly", false);
					} else {
						$("#autoBorrowReserve").attr('checked', false);
						$('#forcastQueueNum').attr({
							style : "background-color: menu"
						});
						$('#forcastOvertime').attr({
							style : "background-color: menu; width:180px"
						});
						$('#forcastQueueNum').attr("readonly", true);
						$('#forcastOvertime').attr("readonly", true);

					}
					if (result.map.IS_EMAIL == "1") {
						$("#autoMailNotice").attr('checked', true);
						document.getElementById("sendSvr").removeAttribute(
								"style");
						document.getElementById("sendPort").removeAttribute(
								"style");
						document.getElementById("rcvSvr").removeAttribute(
								"style");
						document.getElementById("rcvPort").removeAttribute(
								"style");

						$('#sendSvr').attr({
							style : "width: 75%"
						});
						$('#sendPort').attr({
							style : "width: 75%"
						});
						$('#rcvSvr').attr({
							style : "width: 75%"
						});
						$('#rcvPort').attr({
							style : "width: 75%"
						});

						$('#sendSvr').attr("readonly", false);
						$('#sendPort').attr("readonly", false);
						$('#rcvSvr').attr("readonly", false);
						$('#rcvPort').attr("readonly", false);
					} else {
						$("#autoMailNotice").attr('checked', false);
						$('#sendSvr').attr({
							style : "background-color: menu; width: 75%"
						});
						$('#sendPort').attr({
							style : "background-color: menu; width: 75%"
						});
						$('#rcvSvr').attr({
							style : "background-color: menu; width: 75%"
						});
						$('#rcvPort').attr({
							style : "background-color: menu; width: 75%"
						});

						$('#sendSvr').attr("readonly", true);
						$('#sendPort').attr("readonly", true);
						$('#rcvSvr').attr("readonly", true);
						$('#rcvPort').attr("readonly", true);
					}
					if (result.map != "" && result.map != null) {
						$('#defaultUseDays').attr('value',
								result.map.DEFAULT_USE_DAYS);
						$('#defaultBorrowDays').attr('value',
								result.map.DEFAULT_BORROW_DAYS);
						$('#defaultBorrowNum').attr('value',
								result.map.DEFAULT_BORROW_NUM);
						$('#borrowForcastDays').attr('value',
								result.map.BORROW_FORCAST_DAYS);
						$('#forcastQueueNum').attr('value',
								result.map.FORCAST_QUEUE_NUM);
						$('#forcastOvertime').attr('value',
								result.map.FORCAST_OVERTIME);
						$('#psnMsgMaxRcds').attr('value',
								result.map.PSN_MSG_MAX_RCDS);
						$('#sendSvr').attr('value', result.map.SEND_SVR);
						$('#sendPort').attr('value', result.map.SEND_PORT);
						$('#rcvSvr').attr('value', result.map.RCV_SVR);
						$('#rcvPort').attr('value', result.map.RCV_PORT);
						$('#sendEmailCount').attr('value',
								result.map.SEND_EMAIL_COUNT);
						$('#password').attr('value', result.map.PASSWORD);

					}
				}
			});
}


function editDatas() {
	// 恢复input编辑，disabled，false
	editStatus=1;
	$("#appointmentArsDays").attr("disabled", false);
	$("#appointmentArsDays").css("color",'black');
	$("#download_defaultUseDays").attr("disabled", false);
	$("#download_defaultBorrowDays").attr("disabled", false);
	$("#printing_defaultUseDays").attr("disabled", false);
	$("#printing_defaultBorrowDays").attr("disabled", false);
	$("#browse_defaultUseDays").attr("disabled", false);
	$("#browse_defaultBorrowDays").attr("disabled", false);

	$("#borrowing_defaultUseDays").attr("disabled", false);
	$("#borrowing_defaultBorrowDays").attr("disabled", false);
	$("#borrowing_defaultUrgeDays").attr("disabled", false);
	/* 新增浏览(无水印) */
	$("#borrowingNoWatermark_defaultUseDays").attr("disabled", false);
	$("#borrowingNoWatermark_defaultBorrowDays").attr("disabled", false);
	$("#borrowingNoWatermark_defaultUrgeDays").attr("disabled", false);
	/* 新增下载(无水印) */
	$("#downloadNoWatermark_defaultUseDays").attr("disabled", false);
	$("#downloadNoWatermark_defaultBorrowDays").attr("disabled", false);
	$("#downloadNoWatermark_defaultUrgeDays").attr("disabled", false);
	/* 新增纸质借阅 */
	$("#downloadPaper_defaultUseDays").attr("disabled", false);
	$("#downloadPaper_defaultBorrowDays").attr("disabled", false);
	$("#downloadPaper_defaultUrgeDays").attr("disabled", false);

	$("#download_defaultUseDays").css("color",'black');
	$("#download_defaultBorrowDays").css("color",'black');
	$("#printing_defaultUseDays").css("color",'black');
	$("#printing_defaultBorrowDays").css("color",'black');
	$("#browse_defaultUseDays").css("color",'black');
	$("#browse_defaultBorrowDays").css("color",'black');


	$("#borrowing_defaultUseDays").css("color",'black');
	$("#borrowing_defaultBorrowDays").css("color",'black');
	$("#borrowing_defaultUrgeDays").css("color",'black');

	/* 新增浏览(无水印) */
	$("#borrowingNoWatermark_defaultUseDays").css("color",'black');
	$("#borrowingNoWatermark_defaultBorrowDays").css("color",'black');
	$("#borrowingNoWatermark_defaultUrgeDays").css("color",'black');
	/* 新增下载(无水印) */
	$("#downloadNoWatermark_defaultUseDays").css("color",'black');
	$("#downloadNoWatermark_defaultBorrowDays").css("color",'black');
	$("#downloadNoWatermark_defaultUrgeDays").css("color",'black');
	/* 新增纸质借阅 */
	$("#downloadPaper_defaultUseDays").css("color",'black');
	$("#downloadPaper_defaultBorrowDays").css("color",'black');
	$("#downloadPaper_defaultUrgeDays").css("color",'black');
}

// 成功后返回
function succeeds() {
	editStatus=0;
	$("#appointmentArsDays").attr("disabled", true);
	$("#download_defaultUseDays").attr("disabled", true);
	$("#download_defaultBorrowDays").attr("disabled", true);
	$("#printing_defaultUseDays").attr("disabled", true);
	$("#printing_defaultBorrowDays").attr("disabled", true);
	$("#browse_defaultUseDays").attr("disabled", true);
	$("#browse_defaultBorrowDays").attr("disabled", true);

	$("#borrowing_defaultUseDays").attr("disabled", true);
	$("#borrowing_defaultBorrowDays").attr("disabled", true);
	$("#borrowing_defaultUrgeDays").attr("disabled", true);

	/* 新增浏览(无水印) */
	$("#borrowingNoWatermark_defaultUseDays").attr("disabled", true);
	$("#borrowingNoWatermark_defaultBorrowDays").attr("disabled", true);
	$("#borrowingNoWatermark_defaultUrgeDays").attr("disabled", true);
	/* 新增下载(无水印) */
	$("#downloadNoWatermark_defaultUseDays").attr("disabled", true);
	$("#downloadNoWatermark_defaultBorrowDays").attr("disabled", true);
	$("#downloadNoWatermark_defaultUrgeDays").attr("disabled", true);
	/* 新增纸质借阅 */
	$("#downloadPaper_defaultUseDays").attr("disabled", true);
	$("#downloadPaper_defaultBorrowDays").attr("disabled", true);
	$("#downloadPaper_defaultUrgeDays").attr("disabled", true);

	$("#appointmentArsDays").css("color",'#585858');
	$("#download_defaultUseDays").css("color",'#585858');
	$("#download_defaultBorrowDays").css("color",'#585858');
	$("#printing_defaultUseDays").css("color",'#585858');
	$("#printing_defaultBorrowDays").css("color",'#585858');
	$("#browse_defaultUseDays").css("color",'#585858');
	$("#browse_defaultBorrowDays").css("color",'#585858');


	$("#borrowing_defaultUseDays").css("color",'#585858');
	$("#borrowing_defaultBorrowDays").css("color",'#585858');
	$("#borrowing_defaultUrgeDays").css("color",'#585858');

	/* 新增浏览(无水印) */
	$("#borrowingNoWatermark_defaultUseDays").css("color",'#585858');
	$("#borrowingNoWatermark_defaultBorrowDays").css("color",'#585858');
	$("#borrowingNoWatermark_defaultUrgeDays").css("color",'#585858');
	/* 新增下载(无水印) */
	$("#downloadNoWatermark_defaultUseDays").css("color",'#585858');
	$("#downloadNoWatermark_defaultBorrowDays").css("color",'#585858');
	$("#downloadNoWatermark_defaultUrgeDays").css("color",'#585858');
	/* 新增纸质借阅 */
	$("#downloadPaper_defaultUseDays").css("color",'#585858');
	$("#downloadPaper_defaultBorrowDays").css("color",'#585858');
	$("#downloadPaper_defaultUrgeDays").css("color",'#585858');
}

// 保存配置信息
function saveData() {
	if(editStatus==0){ // 未点击编辑
		$.messager.alert("操作提示",
			"没有任何需要保存的数据！", 'warning');
		return;
	}
	var validateFlag = $("#configForm").form('validate');
	if (validateFlag == false) {
		return;
	}
	var list = document.getElementsByTagName("input");
	var strData = "";
	// 对表单中所有的input进行遍历
	for ( var i = 0; i < list.length && list[i]; i++) {
		// 判断是否为文本框
		if (list[i].type == "text") {
			strData += list[i].value;
		}
	}
	if (strData == "" && $("#highSet").attr('checked') == undefined) {
		// commonLang.tip.alert替换'提示',commonLang.optip.save.noConfigData替换"未添加任何配置数据，不能保存！"
		$.messager.alert(commonLang.tip.alert,
				commonLang.optip.save.noConfigData, 'warning');
	} else {
		// 根据flag进行判断到底是新增还是更新，1：更新 2：新增
		if(flag=="1"){ // 更新
			$.ajax({
				url : 'platform/UseConfigController/updataUseData',
				data : {
					sysId:sysId,
				},
				type : 'post',
				dataType : 'json',
				success : function(data) {
				}
			});
			flag=="1";
		}
		// 获取天数数据
		var appointmentArsDays = $('#appointmentArsDays').val();

		var downloaddefaultUseDays = $('#download_defaultUseDays').val();
		var downloaddefaultBorrowDays = $("#download_defaultBorrowDays").val();
		var printingdefaultUseDays = $("#printing_defaultUseDays").val();
		var printingdefaultBorrowDays = $("#printing_defaultBorrowDays").val();
		var browsedefaultUseDays = $("#browse_defaultUseDays").val();
		var browsedefaultBorrowDays = $("#browse_defaultBorrowDays").val();

		var borrowingdefaultUseDays = $("#borrowing_defaultUseDays").val();
		var borrowingdefaultBorrowDays = $("#borrowing_defaultBorrowDays")
				.val();
		var borrowingdefaultUrgeDays = $("#borrowing_defaultUrgeDays").val();

		/* 新增浏览(无水印) */
		var borrowingNoWatermarkdefaultUseDays = $("#borrowingNoWatermark_defaultUseDays").val();
		var borrowingNoWatermarkdefaultBorrowDays = $("#borrowingNoWatermark_defaultBorrowDays").val();
		var borrowingNoWatermarkdefaultUrgeDays = $("#borrowingNoWatermark_defaultUrgeDays").val();
		/* 新增下载(无水印) */
		var downloadNoWatermarkdefaultUseDays = $("#downloadNoWatermark_defaultUseDays").val();
		var downloadNoWatermarkdefaultBorrowDays = $("#downloadNoWatermark_defaultBorrowDays").val();
		var downloadNoWatermarkdefaultUrgeDays = $("#downloadNoWatermark_defaultUrgeDays").val();
		/* 新增纸质借阅 */
		var downloadPaperdefaultUseDays = $("#downloadPaper_defaultUseDays").val();
		var downloadPaperdefaultBorrowDays = $("#downloadPaper_defaultBorrowDays").val();
		var downloadPaperdefaultUrgeDays = $("#downloadPaper_defaultUrgeDays").val();

		$.ajax({
			url : 'platform/UseConfigController/saveArchivalMessage?sysId='
					+ sysId,
			data : {
				"appointmentArsDays" : appointmentArsDays,
				"download_defaultUseDays" : downloaddefaultUseDays,
				"download_defaultBorrowDays" : downloaddefaultBorrowDays,
				"printing_defaultUseDays" : printingdefaultUseDays,
				"printing_defaultBorrowDays" : printingdefaultBorrowDays,
				"browse_defaultUseDays" : browsedefaultUseDays,
				"browse_defaultBorrowDays" : browsedefaultBorrowDays,
				"borrowing_defaultUseDays" : borrowingdefaultUseDays,
				"borrowing_defaultBorrowDays" : borrowingdefaultBorrowDays,
				"borrowing_defaultUrgeDays" : borrowingdefaultUrgeDays,
				/* 新增的天数字段 */
				"borrowingNoWatermarkdefaultUseDays":borrowingNoWatermarkdefaultUseDays,
				"borrowingNoWatermarkdefaultBorrowDays":borrowingNoWatermarkdefaultBorrowDays,
				"borrowingNoWatermarkdefaultUrgeDays":borrowingNoWatermarkdefaultUrgeDays,
				"downloadNoWatermarkdefaultUseDays":downloadNoWatermarkdefaultUseDays,
				"downloadNoWatermarkdefaultBorrowDays":downloadNoWatermarkdefaultBorrowDays,
				"downloadNoWatermarkdefaultUrgeDays":downloadNoWatermarkdefaultUrgeDays,
				"downloadPaperdefaultUseDays":downloadPaperdefaultUseDays,
				"downloadPaperdefaultBorrowDays":downloadPaperdefaultBorrowDays,
				"downloadPaperdefaultUrgeDays":downloadPaperdefaultUrgeDays
			},
			type : 'post',
			dataType : 'json',
			success : function(data) {
				if (data.success == "1") {
					$.messager.alert("操作提示", "保存成功！","info");
					succeeds();
				} else if (data.success == "0") {
					$.messager.alert("操作提示", "保存失败！", "error");
				}
			}
		});
	}
}
